//
//  AuctionCollectionViewDelegate.m
//  MyNewProject
//
//  Created by 王春辉 on 2019/12/22.
//  Copyright © 2019年 sun. All rights reserved.
//

#import "AuctionCollectionViewDelegate.h"
#import "AuctionSellModel.h"

@interface AuctionCollectionViewDelegate()<UICollectionViewDelegateFlowLayout>

@property (nonatomic, copy) AuctionCollectionViewShareButtonClickBlock shareBlock;
@property (nonatomic, copy) AuctionCollectionViewDidSelectAtRowIndexPathBlock selectBlock;
@end

static NSString *const identifier = @"auction_cell_identifier";
static NSString *const headerIdentifier = @"auction_collection_header_identifer";
@implementation AuctionCollectionViewDelegate

#pragma mark -- mark UICollectionViewDelegate UICollectionViewDataSource
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    AuctionCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:identifier forIndexPath:indexPath];
    SKWeakSelf;
    AuctionSellDataModel *model = self.dataArray[indexPath.item];
    [cell.imageView sd_setImageWithURL:[NSURL URLWithString:model.img] placeholderImage:SKIMAGE_NAMED(@"cell_default_img")];
    cell.title = model.title;
    cell.startPrice = [model.price floatValue];
    cell.status = [model.status intValue];
    cell.sinceEndTimeInterval = model.lost_end_time;
    cell.sinceStartTimeInterval = model.lost_begin_time;
    cell.countDownEndBlock = self.countDownEndBlock;
    [cell shareButtonClickBlock:^{
        if (weakSelf.shareBlock) {
            weakSelf.shareBlock(indexPath);}
    }];
    return cell;
}
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    return self.dataArray.count;
}

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
    if (self.selectBlock) {
        self.selectBlock(indexPath); }
}
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout referenceSizeForHeaderInSection:(NSInteger)section {
    return self.headerView.size;
}
/**
 分享按钮点击回调block
 
 @param block block
 */
- (void)shareButtonClockBlock:(AuctionCollectionViewShareButtonClickBlock)block {
    self.shareBlock = block;
}
/**
 cell点击回调block
 
 @param block block
 */
- (void)didSelectItemAtIndexPathBlock:(AuctionCollectionViewDidSelectAtRowIndexPathBlock)block {
    self.selectBlock = block;
}
@end
